home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group94a.txt / 000056_icon-group-sender _Sun Feb 20 18:29:49 1994.msg < prev    next >
Internet Message Format  |  1994-08-19  |  2KB

  1. Received: by cheltenham.cs.arizona.edu; Sun, 20 Feb 1994 19:27:52 MST
  2. From: pab (Peter A. Bigot)
  3. Message-Id: <9402210129.AA26505@omnia.cs.arizona.edu>
  4. Subject: generating both [lr]values of records
  5. To: icon-group
  6. Date: Sun, 20 Feb 1994 18:29:49 -0700 (MST)
  7. X-Mailer: ELM [version 2.4 PL23]
  8. Mime-Version: 1.0
  9. Content-Type: text/plain; charset=US-ASCII
  10. Content-Transfer-Encoding: 7bit
  11. Content-Length: 1807      
  12. Status: RO
  13. Errors-To: icon-group-errors@cs.arizona.edu
  14.  
  15. I have a large number of different records (representing syntactic terms, if
  16. it matters), which form trees, and I want to replace subtrees with a value
  17. which is based on the current subtree (in effect, implement variable
  18. substitution: t [expr/X]).
  19.  
  20. I don't care about the old value of the records, so an update-in-place would
  21. be nice.  I also don't want to enumerate the different types of records, and
  22. handle them with separate cases.  So, using the ! generator on the record,
  23. and the neat trick that it generates lvalues, looks like the way to go.
  24. I.e., "every !rec := expr".  But: how can I use the generated element (of
  25. !rec) as part of the rhs of the assignment?
  26.  
  27. It seems to me I've seen this before, but can't recall the necessary
  28. incantation.
  29.  
  30. Here are a few attempts, one of which works---but I'd like a better way.
  31.  
  32. record A (a1, a2, a3)           # some arbitrary record
  33.  
  34. procedure main ()
  35.     ar := A (1, 2, 3)
  36.  
  37.     # Attempt one:  naively assume we can preserve the lvalue
  38.     every (t := !ar) do
  39.         t := (.t+1)
  40.     writes (image (ar), " -- ")
  41.     every writes (! ar, " ")
  42.     write ()
  43.  
  44.     # Attempt two: maybe we can fool it
  45.     every (t := !ar) := (t+1)
  46.     writes (image (ar), " -- ")
  47.     every writes (! ar, " ")
  48.     write ()
  49.  
  50.     # Brute force: this works, but it's gotta be inefficient in both
  51.     # time and space
  52.     nr := list()
  53.     every put (nr, !ar + 1)
  54.     ar := type(ar) ! nr # -10 points for using arcane features....
  55.     writes (image (ar), " -- ")
  56.     every writes (! ar, " ")
  57.     write ()
  58.  
  59.     # What I'd like:
  60.     # every !ar := (¤tgenelt)+1
  61.     # but for some reason that doesn't work....
  62.  
  63.     end # main
  64.  
  65. Is there a better way?
  66.  
  67. -- 
  68.                      Peter A. Bigot -- pab@CS.Arizona.EDU
  69.           Dept. of Computer Science, University of Arizona, Tucson AZ
  70.